import { Navigate } from "react-router-dom";
import React, { lazy } from "react";
import ErrorRoute from "../components/errorRoute";
const Home = lazy(() => import("../pages/Home"));
// const HomeView = lazy(() => import("../pages/HomeView"));
const ListHome = lazy(() => import("../pages/ListHome"));
const GoodsView = lazy(() => import("../pages/GoodsView"));
const OrderView = lazy(() => import("../pages/OrderView"));
const UsersView = lazy(() => import("../pages/UserView"));
const DictView = lazy(() => import("../pages/DictView"));
const NoticeView = lazy(() => import("../pages/NoticeView"));
// const DictDataView = lazy(() => import("../pages/DictView/Dict_Data"));
const CategoryView = lazy(() => import("../pages/CategoryView"));
const Hello = lazy(() => import("../pages/Hello"));
const Login = lazy(() => import("../pages/Login"));
const Register = lazy(() => import("../pages/Register"));
const ListUsers = lazy(() => import("../pages/ListUsers"));
const ListProducts = lazy(() => import("../pages/ListProducts"));
const ListCategories = lazy(() => import("../pages/ListCategories"));
const ListSuppliers = lazy(() => import("../pages/ListSuppliers"));
const ListPurchaseOrders = lazy(() => import("../pages/ListPurchaseOrders"));
const ListPurchaseNotifications = lazy(
  () => import("../pages/ListPurchaseNotifications")
);
const ListReturnApplications = lazy(
  () => import("../pages/ListReturnApplications")
);
const ListApplications = lazy(() => import("../pages/ListApplications"));

const ListWarehouses = lazy(() => import("../pages/ListWarehouses"));
const ListWarehouseRecords = lazy(
  () => import("../pages/ListWarehouseRecords")
);
const ListWarehouseProducts = lazy(
  () => import("../pages/ListWarehouseProducts")
);

const ResetPassword = lazy(() => import("../pages/ResetPassword"));

// 简化懒加载组件
let lazyComponents = (component: JSX.Element) => {
  return (
    <React.Suspense fallback={<div>加载中...</div>}>{component}</React.Suspense>
  );
};
const routes = [
  {
    path: "/",
    element: <Navigate to="/home" />,
  },
  {
    path: "/",
    element: lazyComponents(<Home />),
    children: [
      {
        name: "首页",
        path: "/home",
        element: lazyComponents(<ListHome />),
      },
      {
        name: "账号列表",
        path: "/list-users",
        element: lazyComponents(<ListUsers />),
      },
      {
        name: "物品列表",
        path: "/list-products",
        element: lazyComponents(<ListProducts />),
      },
      {
        name: "物品种类列表",
        path: "/list-categories",
        element: lazyComponents(<ListCategories />),
      },
      {
        name: "供应商列表",
        path: "/list-suppliers",
        element: lazyComponents(<ListSuppliers />),
      },

      {
        name: "采购订单列表",
        path: "/list-purchase-orders",
        element: lazyComponents(<ListPurchaseOrders />),
      },
      {
        name: "采购通知列表",
        path: "/list-purchase-notifications",
        element: lazyComponents(<ListPurchaseNotifications />),
      },
      {
        name: "归还申请列表",
        path: "/list-return-applications",
        element: lazyComponents(<ListReturnApplications />),
      },
      {
        name: "申请列表",
        path: "/list-applications",
        element: lazyComponents(<ListApplications />),
      },
      {
        name: "仓库列表",
        path: "/list-warehouses",
        element: lazyComponents(<ListWarehouses />),
      },
      {
        name: "仓库列表",
        path: "/list-warehouse-records",
        element: lazyComponents(<ListWarehouseRecords />),
      },
      {
        name: "仓库物品列表",
        path: "/list-warehouse-products",
        element: lazyComponents(<ListWarehouseProducts />),
      },

      {
        name: "密码重置",
        path: "/reset-password",
        element: lazyComponents(<ResetPassword />),
      },

      {
        name: "商品管理",
        path: "/goods",
        element: lazyComponents(<GoodsView />),
      },
      {
        name: "公告管理",
        path: "/notices",
        element: lazyComponents(<NoticeView />),
      },
      {
        name: "订单管理",
        path: "/order",
        element: lazyComponents(<OrderView />),
      },
      {
        name: "用户管理",
        path: "/user",
        element: lazyComponents(<UsersView />),
      },
      {
        name: "分类管理",
        path: "/category",
        element: lazyComponents(<CategoryView />),
      },
      {
        name: "字典管理",
        path: "/dict_types",
        element: lazyComponents(<DictView />),
      },
      // {
      //   name: "字典列表",
      //   path: "/settings/:type_code",
      //   element: lazyComponents(<DictDataView />),
      // },
      {
        name: "sub1",
        path: "/sub1/hello",
        element: lazyComponents(<Hello />),
      },
    ],
  },
  {
    path: "/login",
    element: lazyComponents(<Login />),
  },
  {
    path: "/register",
    element: lazyComponents(<Register />),
  },
  {
    path: "*",
    element: <ErrorRoute />,
  },
];
export default routes;
